<style>
body {
	text-align:center;
	margin:0px;
}

#edit_order_content {
	position: absolute;
	z-index: auto;
	height: auto;
	width: 1000px;
	left:0px;
	top:80px;

}
#edit_order_menu {
	width:400px;
	padding-left:20px;
	height:auto;
	text-align:left;
	
}
#edit_order_top {
	width:500px;
	height:auto;
	margin-top:10px;
	padding-left:200px;
	font-family:"ＭＳ Ｐゴシック", "ＭＳ ゴシック", "ＭＳ Ｐ明朝", "ＭＳ 明朝", "MS UI Gothic";
	font-size:14px;

}

#edit_order_content #testForm table {
	font-family: "ＭＳ Ｐゴシック", "ＭＳ ゴシック", "ＭＳ Ｐ明朝", "ＭＳ 明朝", "MS UI Gothic";
	font-size: 14px;
}
#edit_order_content .Wdate {
	width:150px;
}
</style>
	<!--{include /service/service_head}-->
	<div id="edit_order_content">
	<div id="edit_order_menu">
		<!--{if Session::Get('error')!=null}-->
		<div class="error">
			 ${Session::Get('error', true)}
		</div>
		<!--{/if}-->
	</div>
	<form action="/service/editOrder.php" id="testForm" method="post">
		
	<input type="hidden" name="id" value="{$orderId}">
	<div id="edit_order_top">
		<table cellspacing="0" cellpadding="0" border="0" width="500">
    <tbody>
    <tr>
      <td>&nbsp;</td>
      <td align="right"><label>予約開始時間：</label></td>
      <td>
        <label for="textfield"></label>
        <!--{if $order != null }-->
        <input type="text" name="start_date" value="${date("Y-m-d H:i", $order['service_start_time'])}" onfocus="WdatePicker({lang:'jp', dateFmt:'yyyy-MM-dd HH:mm', minDate:'${date("Y-m-d H:i")}'})" class="Wdate" ><br/>
        <!--{else}-->
        <input type="text" name="start_date" value="${date("Y-m-d H:i")}" onfocus="WdatePicker({lang:'jp', dateFmt:'yyyy-MM-dd HH:mm', minDate:'${date("Y-m-d H:i")}'})" class="Wdate"><br/>
        <!--{/if}-->
      </td>
      <td id="timeError">&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td align="right"><label>予約お客様<!--{if $order['user_id'] < 1  }-->(電話番号)<!--{/if}--></label>&nbsp;：</td>
      <td>
        <!--{if $order['user_id'] > 0 }-->
        <?php $tempUser = Users::GetUser($order['user_id'])?>
        {$tempUser['family_name']} {$tempUser['personal_name']}
        <!--{else}-->
        <input name="tel_no" type="text" value="{$order['back1']}" size="27"/></td>
        <td>　</td></tr>
        <tr><td></td><td align="right"><label>お客様</label>：</td><td>
        	<input name="name" type="text" value="{$order['back2']}" size="27"/>
        <!--<input type="button" id="searchUser" value="search"/>
        --><input type="hidden" name="user_id"/>
        <!--{/if}-->
      </td>
      <td>&nbsp;</td>
    </tr>
    
    <tr>
      <td>&nbsp;</td>
      <td align="right"><label>予約店舗</label>&nbsp;：</td>
      <td>
        <select name="shopId" class="f-city" style="width:100">
			<option value="0" style="width:40">選択してください</option>
			${Utility::Option(Utility::OptionArray($shopList, 'id', 'shop_name'), $defaultShopId)}
		</select>
      </td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td align="right"><label>予約コース{$serviceId}</label>&nbsp;：</td>
      <td>
        <label for="select"></label>
        <select id="select" name="service_id" style="width:150">
           	<option value="0">選択してください</option>
			${Utility::Option(Utility::OptionArray($serviceList, 'id', 'service_name'), $serviceId)}
        </select>
      </td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td align="right"><label>スタッフ指名</label>&nbsp;：</td>
      <td align="right"><label>客様から指名</label>&nbsp;：</td>
      <td><input type="checkbox" value="1" name="isDesignationed"></td>
      <td>
      	<select id="designationStuff" name="staff_id" style="width:150">
           	<option value="0">選択してください</option>
			${Utility::Option(Utility::OptionArray($staffList, 'id', 'family_name', 'personal_name'), $staffId)}
        </select>
       </td>
      <td id="staff_error">&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td align="right"><label>設備</label>&nbsp;：</td>
      <td>
      	<select id="designationStuff" name="device_id" style="width:150">
           	<option value="0">選択してください</option>
			${Utility::Option(Utility::OptionArray($deviceList, 'id', 'device_name'), $deviceId)}
        </select>
       </td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td align="right"><label>予約終了時間</label>&nbsp;：</td>
      <td>
      	<!--{if $order != null }-->
      	<input type="text" id="end_time" name="endHour" size="2" readonly="readonly" value="${date("H", $order['service_end_time']) * 1}"/>
      	<input type="text" id="end_time" name="endMinute" size="2" readonly="readonly" value="${date("i", $order['service_end_time']) * 1}"/>
      	<!--{else}-->
      	<input type="text" id="end_time" name="endHour" size="2" readonly="readonly" value="${date("H") * 1}"/>
      	<input type="text" id="end_time" name="endMinute" size="2" readonly="readonly" value="${date("i") * 1}"/>
      	 <!--{/if}-->
      </td>
      <td><input type="submit"/></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </tbody></table>
	<div>
	</form>
	<div>
		<a href="{$_SERVER['HTTP_REFERER']}">戻る</a>
	</div>
	</div>
</body>
</html>
<script type="text/javascript"> 
var serviceCache = [];
var timeError = false;
var staffError = false;
var userError = false;
var tempCalendar = null;
$(document).ready(function(){

		

		if( $("#searchUser").length > 0 ){
			$("#searchUser").bind("click", function(e){
				$("#searchUser").next("span").remove();
				$.get("{$webRoot}/service/searchUser.php", "email=" + $("input[name='email']").val(), function(data){
					if( data.error != 0 ){
						alert("ユーザ見つかりませんでした。");
						return ;
					}
					$("input[name='user_id']").val( data.data['id'] );
					$("#searchUser").after("<span>" + data.data['family_name'] + data.data['personal_name'] + "</span>");
				}, "json");
			})
		}
	
	$("#testForm").bind("submit", function(){
		if(staffError == true){
			$("#staff_error").html("ご指名スタッフはこの時間で予約取れませんの為に、ご予約できませんでした。").show();
			return false;
		}else{
			$("#staff_error").html("").hide();
		}
		return !timeError
		
	})
	
	$("input[name='start_date']").bind("blur", function(){
		calTime();
		getStaffs();
	})
	$("input[name='startMinute']").bind("blur", function(){
		calTime();
		getStaffs();
	})
	
	$("select[name='shopId']").bind("change", function(){
		if( $(this).val() < 1 ){
			return ;
		}
		$.get("{$webRoot}/ajax/GetServiceList.php", "shopId=" + $(this).val(), function(data){
			var options = '<option value="0">選択してください</option>';
			for(var index in data.data){
				if( !index ){
					continue;
				}
				options = options + '<option value="' + index + '">' + data.data[index].service_name + '</option>';
				serviceCache[index] = data.data;
			}
			$("select[name='service_id']").html(options);
		}, "json");
		
	});


	$("select[name='service_id']").bind("change", function(){
		calTime();
		getStaffs();
		
	});
});


function getStaffs(){
	if( $("select[name='shopId']").val() < 1 || $("input[name='startHour']") < 1 || $("select[name='service_id']").val() < 1){
		return ;
	}
	var data = "shopId=" + $("select[name='shopId']").val() + "&serviceId=" +$("select[name='service_id']").val();
	data = data + "&startHour=" + $("input[name='startHour']").val() + "&startMinute=" + $("input[name='startMinute']").val() + 
		"&endHour=" + $("input[name='endHour']").val() + "&endMinute=" + $("input[name='endMinute']").val();
	data = data + "&start_date=" + $("input[name='start_date']").val();
	data = data + "&id=" + $("input[name='id']").val();
	$.get("{$webRoot}/ajax/GetStaffList.php", data, function(data){
		if( data.error != 0 ){
			$("select[name='staff_id']").html('<option value="0">選択してください</option>');
			staffError = true;
			return ;
		}
		staffError = false;
		$("#staff_error").hide();
		var options = '<option value="0">選択してください</option>';
		for(var index in data.data){
			if( !index ){
				continue;
			}
			options = options + '<option value="' + index + '">' + data.data[index] + '</option>';
			serviceCache[index] = data.data;
		}
		$("select[name='staff_id']").html(options);
	}, "json");
}


function calTime(){
	
	var data = "shopId=" + $("select[name='shopId']").val() + "&serviceId=" +$("select[name='service_id']").val();
	data = data + "&startHour=" + $("input[name='startHour']").val() + "&startMinute=" + $("input[name='startMinute']").val();
	data = data + "&start_date=" + $("input[name='start_date']").val();
	data = data + "&id=" + $("input[name='id']").val();
	$.get("{$webRoot}/ajax/CalcEndTime.php", data, function(data){
		if( data.error == 0 ){
			$("#timeError").hide();
			timeError = false;
			for(var index in data.data){
				$("input[name='endHour']").val(data.data['endHour']);
				$("input[name='endMinute']").val(data.data['endMinute']);
			}
		}else{
			$("#timeError").html(data.data).show();
			timeError = true;
		}
		
	}, "json");
}
</script> 
</html> 